using System;
using System.Collections;
using System.Web;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;

namespace Sedna.Core.Controls.Actions
{
	/// <summary>
	/// Validate date entered in date picker
	/// </summary>
	public class ValidateDateAction: AbstractValidationAction
	{
	    private DateTime minDate = new DateTime(1901,1,1);
	    private DateTime maxDate = new DateTime(9999,12,31);

	    public DateTime MinDate
	    {
	        set { minDate = value; }
	    }

	    public DateTime MaxDate
	    {
	        set { maxDate = value; }
	    }

	    protected override bool Validate(IExecutionContext executionContext, string validationValue)
		{
            DateTime res;
	        return ((DateTime.TryParse(validationValue, out res) && res.CompareTo(minDate) > 0 && res.CompareTo(maxDate) < 0) || (validationValue == null || validationValue.Trim() == string.Empty));
		}
	}
}
